package org.darcy.controller.check;

import java.util.List;

import org.darcy.entity.CheckPlan;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.framework.model.R;
import org.darcy.service.check.CheckPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;


@Tag(name="CheckPlan接口：采样计划")
@RestController
@RequestMapping(value="/CheckPlan")
@Slf4j
public class CheckPlanController  {
	
	private final String info_prefix = "[采样计划模块]";

	@Autowired
	private CheckPlanService checkPlanService;

	@Operation(summary = "所有采样计划列表")
	@GetMapping(value = "getAll")
	public R getAll(Integer clientId) {
		log.debug("{}-所有采样计划列表", info_prefix);
		List<CheckPlan> data = checkPlanService.getAll(clientId);
		return R.ok().data(data);
	}

	@Operation(summary="采样计划分页列表")
	@PostMapping(value = "list")
	public R list(@RequestBody PageParam<CheckPlan> param){
		log.debug("{}-列表数据", info_prefix);
		PageData<CheckPlan> data =  checkPlanService.page(param);
		return R.ok().data(data);
	}


	@Operation(summary="采样计划详情")
	@GetMapping("/view/{id}")
	public R view(@PathVariable Integer id){
		log.debug("{}-查看采样计划信息", info_prefix);
		CheckPlan data = checkPlanService.getDetail(id);
		return R.ok().data(data);
	}
	

	@Operation(summary = "新增采样计划")
	@PostMapping("add")
	public R add(@RequestBody CheckPlan  record) {
		log.debug("{}-新增CheckPlan: {}", info_prefix,  record);
		checkPlanService.insert(record);
		return R.ok("新增成功").data(record);
	}

	
	@Operation(summary = "根据ID删除采样计划")
	@PostMapping("/del/{id}")
	public R del(@PathVariable Integer id){
		log.debug("{}-根据ID删除", info_prefix, id);
		checkPlanService.delete(id);
		return R.ok("删除成功");
	}

	
	@Operation(summary="更新采样计划")
	@PostMapping("update")
	public R update(@RequestBody CheckPlan  record){
		log.debug("{}-保存信息: {}", info_prefix, record);
		checkPlanService.update(record);
		return R.ok("更新成功");
	}
	
	@Operation(summary = "查看采样计划属性")
	@GetMapping("/model")
	public CheckPlan model() {
		return null;
	}
	
}
